package com.reverie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.reverie.entity.CouponLog;
import com.reverie.mapper.CouponLogMapper;
import com.reverie.service.ICouponLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Rui.Zhou
 * @since 2024-02-03
 */
@Service
public class CouponLogServiceImpl extends ServiceImpl<CouponLogMapper, CouponLog> implements ICouponLogService {

    @Override
    public boolean deleteByUserIdAndOrderId(Integer userId, Integer orderId) {
        QueryWrapper<CouponLog> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(CouponLog::getUserId,userId);
        wrapper.lambda().eq(CouponLog::getOrderId,orderId);
        return remove(wrapper);
    }

    @Override
    public boolean addLog(Integer userId, String couponId, Integer orderId) {
        CouponLog couponLog = new CouponLog();
        couponLog.setUserId(userId);
        couponLog.setCouponId(couponId);
        couponLog.setOrderId(orderId);
        couponLog.setAddTime((int) (System.currentTimeMillis() / 1000));
        return saveOrUpdate(couponLog);
    }
}
